package net.oov.identify.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Deprecated
public class Products {
	
	private static ArrayList<CharSequence> productsNameStrs;//beef to cut
	
	/**
	 * load product name to discern new word
	 * @param pathIn
	 * @throws IOException 
	 * @throws IOException
	 */
	public static void loadProducts(String pathIn) throws IOException{
		if(productsNameStrs==null){
			productsNameStrs = new ArrayList<CharSequence>();
			BufferedReader reader = IOUtil.getReader(pathIn, "UTF-8") ;
			String temp = null ;
			while((temp=reader.readLine())!=null){
				//��ȥ�������ַ�
		        //Pattern p = Pattern.compile("[\\x00-\\xff]||[a-zA-Z0-9]||[\\s]||[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~��@#��%����&*��������+|{}������������������������]+");
//				Pattern p = Pattern.compile("[^\u4e00-\u9fa5][\\s]");
//		        Matcher m = p.matcher(temp);
//		        temp = m.replaceAll(" ");
				temp = temp.replaceAll("([^\u4e00-\u9fa5^a-zA-Z0-9])+", " ");
				temp = temp.replaceAll("[a-zA-Z0-9]{2,}", "");
				Pattern p = Pattern.compile("^[\\s]*[a-zA-Z0-9]+[\\s]*$");//����ĸ���ֺ���
				Matcher m = p.matcher(temp);
				if(m.find()){
					continue;
				}
		        for(String str:temp.trim().split(" ")){
		        	productsNameStrs.add(str);
		        }
			}
			reader.close() ;
		}
	}
	
	public static ArrayList<CharSequence> getProducts(String pathIn){
		if(productsNameStrs==null){
			try {
				loadProducts(pathIn);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return productsNameStrs;
	}
	
	public static void main(String[] args){
		List<CharSequence> list = getProducts("text/out1.txt");
		for(CharSequence cs:list){
			wl(cs);
		}
	}
	public static void wl(Object s){
		System.out.println(s);
	}
}
